<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            二当家的Lay1.0
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/static/css/x-admin.css" media="all">
        <link rel="stylesheet" href="/static/lib/layui/css/layui.css"  media="all">
        <link rel="stylesheet" href="/static/cityJSON.txt"  media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form" id="orgForm">
                <div class="layui-form-item">
                    <label for="username" class="layui-form-label" method="post">
                        	机构名称：
                    </label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="orgIdStr" value=${orgInfo.id }>
						<input type="text" name="name" id="orgName" lay-verify="required"
                        autocomplete="off" class="layui-input" value=${orgInfo.name}> <span id="nameSpan"
										style="color: red;">*</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="phone" class="layui-form-label">
                        	省份：
                    </label>
                    <div class="layui-input-inline">
                        <select id="provinces" lay-filter="prov" name="province">
                        	<option>请选择省份</option>
                        </select>
                      </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        	城市：
                    </label>
                    <div class="layui-input-inline">
                        <select id="selCity" name="city">
                        	<option>请选择城市</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="role" class="layui-form-label">
                        	机构地址：
                    </label>
                    <div class="layui-input-inline">
                      <input type="text" name="address" id="email" lay-verify="required"
                        autocomplete="off" class="layui-input redStar" value=${orgInfo.address}><span id="addressSpan" style="color: red">*</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_pass" class="layui-form-label">
                        	机构电话：
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="tel" id="date" lay-verify="required"
                        autocomplete="off" class="layui-input redStar" value=${orgInfo.tel}><span id="telSpan" style="color: red">*</span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        	机构邮编：
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="post"class="layui-input redStar" value=${orgInfo.post}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                          	机构网站：
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" name="url" class="layui-input redStar" value=${orgInfo.url}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        	联系人：
                    </label>
                    <div class="layui-input-inline">
                        <select name="contactName">
										<#list contactList as contact>
										<#if orgInfo.contactId=contact.id>
										<option value=${contact.id } selected>${contact.name }</option>
										<#else >
										<option value=${contact.id } >${contact.name }</option>
										</#if>
										</#list>
									</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        	重要级别：
                    </label>
                    <div class="layui-input-inline">
                        <select name="important" lay-filter="important" value=${orgInfo.important} > 
										<option />一般
										<option />重要
										<option />很重要
										<option />非常重要
									</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        	机构类别：
                    </label>
                    <div class="layui-input-inline">
                        <select name="orgKindName" value=${orgInfo.orgKindName}>
                        <#if orgInfo.orgKindId=1>
										<option value="1" selected/>省级
										<option value="2"/>市级
										<#else>
										<option value="1" />省级
										<option value="2" selected/>市级
										</#if>
									</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        	经办人：
                    </label>
                    <div class="layui-input-inline">
                    	<input type="hidden" name="tradeIdStr" value=${trade.id }>
                        <select name="operatorName">
							<#list staffList as staff>
							<#if trade.operatorId=staff.id>
							<option value=${staff.id } selected>${staff.name }</option> 
							<#else>
							<option value=${staff.id }>${staff.name }</option> 
							</#if>
								
							</#list>
						</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        	采购时间：
                    </label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="自定义日期格式" name="dateStr"
                        onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" value='${trade.buyDateStr}'>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red">*</span>商机状态：
                    </label>
                    <div class="layui-input-inline">
                        <select name="busStatus" value=${trade.busStatus}>
										<option />一般
										<option />重要
										<option />很重要
										<option />非常重要
									</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red">*</span>采购途径：
                    </label>
                    <div class="layui-input-inline">
                        <select name="buyWay" value=${trade.buyWay}>
										<option />直接采购
										<option />招标采购
										<option />代理采购
									</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red">*</span>合同编号：
                    </label>
                    <div class="layui-input-inline">
                        <select name="pactId"> <#list
										pactList as pact>
										<option>${pact.id }</option> </#list>
									</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red">*</span>产品编号：
                    </label>
                    <div class="layui-input-inline">
                        <select name="proIdStr"> <#list
										proList as pro>
										<option>${pro.id }</option> </#list>
									</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        <span class="x-red">*</span>跟进状态：
                    </label>
                    <div class="layui-input-inline">
                        <select name="followStatus" value=${trade.followStatus}>
										<option />初访
										<option />意向
										<option />潜在
										<option />报价
										<option />成交
										<option />暂时搁置
									</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                        	备注：
                    </label>
                    <div class="layui-input-inline">
                        <textarea name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        确认提交
                    </button>
                </div>
            </form>
        </div>
        <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script src="/static/js/x-layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/jquery.min.js"></script>
		<script type="text/javascript" src="/static/cityJSON.txt"></script>
		<script type="text/javascript">
		$(document)
				.ready(
						function() {
							
							//读取json数组
							var jsonAry = eval(json);
							//遍历获取省份并加载列表
							for (var i = 0; i < jsonAry.length; i++) {
								var provinceName = jsonAry[i].name;
								$('#provinces').append(
										"<option>" + provinceName + "</option>");
							};
							var proJson;
							var cityAry
							if('${orgInfo}' == ''){
								$("#orgH1").html('添加机构');
								//获取北京json						
								proJson = jsonAry[0];
								cityAry= proJson["北京市"];
							}else{
								$("#orgH1").html('修改机构');
								for (var i = 0; i < jsonAry.length; i++) {
									//遍历json对象
									for (var key in jsonAry[i]) {
										if (key == '${orgInfo.province}') {
											cityAry = jsonAry[i][key];
											break;
										};
									};
								};
							}
							for (var i = 0; i < cityAry.length; i++) {
								$('#selCity').append("<option>"+ cityAry[i]+ "</option>");
							};
							if ('${orgInfo}' == '') {
								$("#submitbt").attr('disabled', true);
							} else {
								$('#nameSpan').html('');
								$('#addressSpan').html('');
								$('#telSpan').html('');
								//修改页面表单赋值
								$("[name='province']").val('${orgInfo.province}');
								$("[name='city']").val('${orgInfo.city}');
								$("[name='important']").val('${orgInfo.important}');
								$("[name='busStatus']").val('${trade.busStatus}');
								$("[name='buyWay']").val('${trade.buyWay}');
								$("[name='pactId']").val('${trade.pactId}');
								$("[name='proIdStr']").val('10');
								$("[name='remark']").val('${trade.remark}');
							};
							layui.use('form', function () {
						        var form = layui.form();
						        form.on('select(prov)', function(data) {
						          //先移除city列表
									$("#selCity").find("option").remove();
									//省份名
									var selPro = data.value;
									//遍历jsonAry
									for (var i = 0; i < jsonAry.length; i++) {
										//遍历json对象
										for (var key in jsonAry[i]) {
											if (key == selPro) {
												cityAry = jsonAry[i][key];
												for (var i = 0; i < cityAry.length; i++) {
													$('#selCity').append("<option>"+ cityAry[i]+ "</option>");
												};
												form.render('select');
												return;
											};
										};
									};
						        });
						    });
							//省份改变，修改城市列表
							$("#provinces").change(function(event) {
								
								
							});
							$("[name='name']").blur(function() {
								if ($(this).val() == '') {
									$("#nameSpan").html("机构名称不能为空");
									$("#nameSpan").css('color', 'red');
								} else {
									$("#nameSpan").html("");
								}
	
							});
							$("[name='address']").blur(function() {
								if ($(this).val() == '') {
									$("#addressSpan").html("地址不能为空");
									$("#addressSpan").css('color', 'red');
								} else {
									$("#addressSpan").html("");
								}
							});
							$("[name='tel']").blur(function() {
								if ($(this).val() == '') {
									$("#telSpan").html("电话不能为空");
									$("#telSpan").css('color', 'red');
								} else {
									$("#telSpan").html("");
								}
							});
							$(".redStar").change(function() {
								$("#submitbt").attr('disabled', false);
								$(".redStar").each(function() {
									if ($(this).val() == "") {
										$("#submitbt").attr('disabled', true);
									}
								});
							});
							$("[name='contactName']").click(function() {
								$.ajax({
									type : 'post',
									url : 'getContactId',
									data : "contactName=" + $(this).val(),
									success : function(data) {
										$("[name='contactIdStr']").val(data);
									}
								});
							});
							$("[name='operatorName']").click(function() {
								$.ajax({
									type : 'post',
									url : 'getOperatorId',
									data : "operatorName=" + $(this).val(),
									success : function(data) {
										$("[name='operatorIdStr']").val(data);
									}
								});
							});
							$("#submitbt").click(function() {
										if ('${orgInfo}' == '') {
											if (confirm("确认添加？")) {
												$("#orgForm").attr("action",
														"addOrgAction");
												$("#orgForm").submit();
											}
										} else {
											if (confirm("确认修改？")) {
												$("#orgForm").attr("action",
														"updateOrgAction");
												$("#orgForm").submit();
											}
										}
							});
						});
            layui.use(['form','layer'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;
            
              //自定义验证规则
              form.verify({
                nikename: function(value){
                  if(value.length < 5){
                    return '昵称至少得5个字符啊';
                  }
                }
                ,pass: [/(.+){6,12}$/, '密码必须6到12位']
                ,repass: function(value){
                    if($('#L_pass').val()!=$('#L_repass').val()){
                        return '两次密码不一致';
                    }
                }
              });
              //监听提交
              form.on('submit(add)', function(data){
            	  if ('${orgInfo}' == '') {
            		  $.ajax({
            			  data:$('#orgForm').serialize(),
            			  url:"addOrgAction",
            		  	  type:"post",
            		  	  success:function(){
            		  		layer.alert("增加成功", {icon: 6},function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                //关闭当前frame
                                parent.layer.close(index);
                                parent.location.reload();
                            });
            		  	  }
            		  });
            		  
					} else {
						$.ajax({
							  data:$('#orgForm').serialize(),
	            			  url:"updateOrgAction",
	            		  	  type:"post",
	            		  	  success:function(){
	            		  		layer.alert("修改成功", {icon: 6},function () {
	                                // 获得frame索引
	                                var index = parent.layer.getFrameIndex(window.name);
	                                //关闭当前frame
	                                parent.layer.close(index);
	                                parent.location.reload();
	                            });
	            		  	  },
							  
	            		  });
						
					}
                return false;
              });
            });
            layui.use('laydate', function(){
            	  var laydate = layui.laydate;
            	  
            	  var start = {
            	    min: laydate.now()
            	    ,max: '2099-06-16 23:59:59'
            	    ,istoday: false
            	    ,choose: function(datas){
            	      end.min = datas; //开始日选好后，重置结束日的最小日期
            	      end.start = datas //将结束日的初始值设定为开始日
            	    }
            	  };
            	  
            	  var end = {
            	    min: laydate.now()
            	    ,max: '2099-06-16 23:59:59'
            	    ,istoday: false
            	    ,choose: function(datas){
            	      start.max = datas; //结束日选好后，重置开始日的最大日期
            	    }
            	  };
            	  
            	  document.getElementById('LAY_demorange_s').onclick = function(){
            	    start.elem = this;
            	    laydate(start);
            	  }
            	  document.getElementById('LAY_demorange_e').onclick = function(){
            	    end.elem = this
            	    laydate(end);
            	  }
            	  
            	});
        </script>
        <script>
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
        </script>
    </body>

</html>